package com.sany.hibernate.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.hibernate3.HibernateTemplate;

import entity.sys.MonitorLog;

public class MonitorLogDao extends HibernateDaoSupport{
	private static final Log log = LogFactory.getLog(MonitorLogDao.class);
	public HibernateTemplate getHibernateTemplate_(){
		return HibernateGetBean.getHibernateBean("MonitorLogDao").getHibernateTemplate();
	}
	
    public void save(MonitorLog MonitorLogInstance) {
        log.debug("saving MonitorLog instance");
        try {
            getHibernateTemplate_().save(MonitorLogInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
    
	public void delete(MonitorLog persistentInstance) {
        log.debug("deleting MonitorLog instance");
        try {
            getHibernateTemplate_().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
	
	
    public MonitorLog findById(java.lang.Integer id) {
        log.debug("getting MonitorLog instance with id: " + id);
        try {
        	MonitorLog instance = (MonitorLog) getHibernateTemplate_()
                    .get("entity.sys.MonitorLog", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    public List findByExample(MonitorLog instance) {
        log.debug("finding MonitorLog instance by example");
        try {
            List results = getHibernateTemplate_().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }
    
    public List findByProperty(String propertyName, Object value) {
        log.debug("finding MonitorLog instance with property: " + propertyName
              + ", value: " + value);
        try {
           String queryString = "from MonitorLog as model where model." 
           						+ propertyName + "= ?";
  		 return getHibernateTemplate_().find(queryString, value);
        } catch (RuntimeException re) {
           log.error("find by property name failed", re);
           throw re;
        }
  	}
    
    public MonitorLog merge(MonitorLog detachedInstance) {
        log.debug("merging MonitorLog instance");
        try {
        	MonitorLog result = (MonitorLog) getHibernateTemplate_()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }
    
    public void attachDirty(MonitorLog instance) {
        log.debug("attaching dirty MonitorLog instance");
        try {
            getHibernateTemplate_().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(MonitorLog instance) {
        log.debug("attaching clean MonitorLog instance");
        try {
            getHibernateTemplate_().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
	
	public List find(String queryString){
		return getHibernateTemplate_().find(queryString);
	}
	
}
